import {
  evalEl,
  sortKey,
  submitDealReq,
  evalElKeyInVal,
  initSessionFormDataMethod, initSessionUIDataMethod
} from './auth'
import { getBtnDefVal, getOperatorDefVal } from './hyopen'
import { changeFormRowActiveData } from './hyform'
import { changeToolbar, changeToolbarMenu, initColumnListBtn } from '@/utils/hybtn'
import { inputChangeEventControlObj } from './hyctr'
import { getRemoteUrlParam, getRemoteUrlDataSetKey, getCommonRemoteUrlVerify } from '@/utils/hyurl'
import { hasModalFn } from './hyfn'
import {hasBtnModalFn} from "./hybtn";
export function testList() {
  // this.$message.success('test list')
}

/**
 * 初始化字段列表
 * @param thisObj
 */
export function initColumnList(thisObj) {
  if (thisObj.initUiVal.columnsList !== undefined) {
    thisObj.titleIconList = thisObj.initUiVal.columnsList.titleIconList
    thisObj.initLoadObj.loadListId = thisObj.initUiVal.columnsList.loadListId
    thisObj.showAction = thisObj.initUiVal.columnsList.columnBtnKey
    // thisObj.tableColumns = thisObj.initUiVal.columnsList.column
    thisObj.showTags = Object.assign([], thisObj.initUiVal.columnsList.showTags)
  }
  changeListColActiveData(thisObj, thisObj.globalData)
  initListColActive(thisObj, thisObj.globalData)
}

export function changeListColActiveData(thisObj, globalData) {
  let activeColumnData = {}
  if (thisObj.initUiVal.columnsList !== undefined) {
    let listKey = thisObj.initUiVal.columnsList.listKey
    const listData = thisObj.initUiVal.columnsList.listData
    let appListData = {}
    if (thisObj.initUiVal.sessionData !== undefined && thisObj.initUiVal.sessionData.sessionList !== undefined) {
      // 个性配置,以个性配置优先
      if (thisObj.initUiVal.sessionData.sessionList.listKey.length > 0) {
        listKey = thisObj.initUiVal.sessionData.sessionList.listKey
        appListData = thisObj.initUiVal.sessionData.sessionList.listData
      }
    } else if (thisObj.initUiVal.appData !== undefined && thisObj.initUiVal.appData.appList !== undefined) {
      // 存在定制应用,以定制应用配置为主
      if (thisObj.initUiVal.appData.appList.listKey.length > 0) {
        listKey = thisObj.initUiVal.appData.appList.listKey
        appListData = thisObj.initUiVal.appData.appList.listData
      }
    }
    for (const i in listKey) {
      const key = listKey[i]
      const activeTmpData = getActiveColumnData(thisObj, key, listData, globalData)
      if (appListData[key] !== undefined) {
        if (activeTmpData[key].objEl === undefined) {
          // 只支持简单呈现字段替换名称,规则表达式字段不支持
          activeTmpData[key].title = appListData[key].title
        }
      }
      if (activeTmpData !== null) {
        activeColumnData = Object.assign({}, activeColumnData, activeTmpData)
      }
    }
  }
  thisObj.listColActiveData = Object.assign({}, activeColumnData)
}

export function initListColActive(thisObj, globalData) {
  if (thisObj.initUiVal.columnsList !== undefined) {
    const activeListKey = thisObj.initUiVal.columnsList.activeListKey
    changeListColActive(thisObj, activeListKey, globalData)
    thisObj.activeListKey = activeListKey
  }
}

export function hiddenActiveListKey(thisObj, key, globalData) {
  const showList = []
  const tmpActiveList = thisObj.listColActiveList
  for (const i in tmpActiveList) {
    const tmpData = tmpActiveList[i]
    if (tmpData.dataIndex !== key) {
      showList.push(tmpData)
    }
  }
  thisObj.listColActiveList = Object.assign([], sortKey(showList, 'sort'))
}

export function showActiveListKey(thisObj, key, globalData) {
  const showList = []
  const tmpActiveList = thisObj.listColActiveList
  for (const i in tmpActiveList) {
    const tmpData = tmpActiveList[i]
    if (tmpData.dataIndex !== key) {
      showList.push(tmpData)
    }
  }
  if (thisObj.initUiVal.columnsList !== undefined) {
    const listData = Object.assign({}, {}, thisObj.initUiVal.columnsList.listData)
    const newActiveData = getActiveColumnData(thisObj, key, listData, globalData)
    if (newActiveData !== undefined && newActiveData !== null) {
      thisObj.listColActiveData[key] = newActiveData[key]
      showList.push(newActiveData[key])
    }
  }
  thisObj.listColActiveList = Object.assign([], sortKey(showList, 'sort'))
}

export function changeMoreListColActive(thisObj, globalData) {
  const activeListKey = thisObj.initUiVal.columnsList.activeListKey
  const moreListKey = thisObj.initUiVal.columnsList.moreListKey
  const activeKey = Object.assign([], activeListKey, moreListKey)
  changeListColActive(thisObj, activeKey, globalData)
}
export function changeListColActive(thisObj, activeListKey, globalData) {
  const activeColumnList = []
  for (const i in activeListKey) {
    const tmpColumn = activeListKey[i]
    const key = tmpColumn.dataIndex
    if (!evalEl(tmpColumn.objEl, globalData.globalParam)) {
      continue
    }
    const activeData = thisObj.listColActiveData[key]
    if (activeData !== undefined) {
      activeColumnList.push(activeData)
    }
  }
  thisObj.listColActiveList = Object.assign([], activeColumnList)
}
export function hasListModalFn(thisObj, globalData, btnKey) {
  return hasModalFn(thisObj, globalData, 'list', btnKey)
}
export function getActiveColumnData(thisObj, key, listData, globalData) {
  const activeColumnData = {}
  const keyArr = listData[key]
  if (keyArr === undefined) {
    return null
  }
  for (const j in keyArr) {
    const column = keyArr[j]
    const objEl = column.objEl
    if (objEl !== undefined) {
      console.log('column', column, globalData.globalParam)
    }
    if (!evalEl(objEl, globalData.globalParam)) {
      continue
    }
    const hasListFn = hasListModalFn(thisObj, globalData, key)
    if (!hasListFn[key]) {
      continue
    }
    const elKeyResult = evalElKeyInVal(column.elKey, column.elKeyInVal, globalData.globalParam)
    if (!elKeyResult) {
      continue
    }
    const activeLocalColumnData = getLocalColumnData(thisObj, column)
    activeColumnData[key] = Object.assign({}, activeLocalColumnData)
    if (objEl !== undefined) {
      console.log('activeColumnData', activeColumnData)
    }
    return activeColumnData
  }
  return null
}

export function changeColumnList(thisObj, triggerObj, globalData) {
  if (thisObj.initUiVal.columnsList !== undefined) {
    const columnsList = thisObj.initUiVal.columnsList.column
    const cc = changeColumnListData(thisObj, columnsList, globalData)
    thisObj.tableColumns = Object.assign([], cc)
  }
}

export function changeColumnListData(thisObj, columnsList, globalData) {
  // 一开始每次加载字段
  const changeColumnsList = Object.assign([])
  if (columnsList !== undefined && columnsList.length > 0) {
    for (const i in columnsList) {
      const columnData = columnsList[i]
      const tmpData = changeColumnListKey(thisObj, columnData, globalData)
      if (tmpData !== null && tmpData.show) {
        changeColumnsList.push(tmpData)
      }
    }
  }
  return changeColumnsList
}

export function changeColumnListKey(thisObj, columnData, globalData) {
  if (undefined === columnData || columnData === null) {
    return null
  }
  const dataIndex = columnData.dataIndex
  const customColumn = thisObj.customColumn[dataIndex]
  if (customColumn !== undefined && customColumn === false) {
    // 自定义呈现属性,配置了对应属性,并且值为false
    return null
  }
  const elResult = evalEl(columnData.objEl, globalData.globalParam)
  if (!elResult) {
    return null
  }
  const elKeyResult = evalElKeyInVal(columnData.elKey, columnData.elKeyInVal, globalData.globalParam)
  if (!elKeyResult) {
    return null
  }
  const tmpData = getLocalColumnData(thisObj, columnData)
  return tmpData
}

export function getLocalColumnData(thisObj, columnData) {
  if (undefined === columnData || columnData === null) {
    return columnData
  }
  const tmpData = Object.assign({}, columnData)
  tmpData.show = true
  tmpData.align = columnData.align
  tmpData.dataIndex = columnData.dataIndex
  tmpData.defaultShow = 1
  if (undefined !== columnData.key) {
    tmpData.key = columnData.key
  }
  const tmp = columnData.title + '<a-icon type="info-circle" />'
  tmpData.title = columnData.title

  if (undefined !== columnData.refOpenList) {
    tmpData.refOpenList = columnData.refOpenList
  }
  if (undefined !== columnData.scopedSlots) {
    tmpData.scopedSlots = columnData.scopedSlots
  }
  if (tmpData.orderFlag === 2) {
    tmpData.sorter = true
  }
  if (tmpData.filterFlag === 2) {
    const filter = { filterDropdown: 'filterDropdown', filterIcon: 'filterIcon' }
    tmpData.scopedSlots = Object.assign({}, filter, tmpData.scopedSlots)
  } else if (tmpData.filterFlag === 3) {
    thisObj.columnFiltersData[columnData.dataIndex] = tmpData.data
    thisObj.activeFilters.push(columnData.dataIndex)
    tmpData.filters = []
  }

  if (undefined !== columnData.customCell) {
    tmpData.customCell = this.processCustomCell
  }

  tmpData.width = columnData.width
  if (tmpData.fixed !== undefined) {
    // tmpData.fixed = tmpData.fixed
    tmpData.key = tmpData.dataIndex
  }

  if (undefined !== columnData.elKey) {
    tmpData.elKey = columnData.elKey
  }

  if (undefined !== columnData.elKeyInVal) {
    tmpData.elKeyInVal = columnData.elKeyInVal
  }
  if (columnData.slots !== undefined) {
    tmpData.title = undefined
  }
  return tmpData
}

/**
 * 初始化表格事件
 * @param thisObj
 */
export function initTableEvent(thisObj) {
  let tmpEventList = Object.assign([])
  if (thisObj.initUiVal.tblList !== undefined) {
    if (thisObj.initUiVal.tblList.event !== undefined) {
      tmpEventList = thisObj.initUiVal.tblList.event[thisObj.initTableKey]
    }
  }
  thisObj.initTableEvent = Object.assign([], tmpEventList)
}
/**
 * 初始化表格事件
 * @param thisObj
 * @param eventName 事件函数(单击，双击,选择)
 * @param eventName中文
 */
export function changeTableEvent(thisObj, eventName, name, globalData) {
  const changeEventList = Object.assign([])
  for (const i in thisObj.initTableEvent) {
    const tableEvent = thisObj.initTableEvent[i]
    if (tableEvent.s_OBJ_EVENT === eventName) {
      changeEventList.push(tableEvent)
    }
  }
  // const record = Object.assign({}, thisObj.openParam, thisObj.initData, thisObj.formModel, clickRow)
  if (changeEventList.length > 0) {
    const tableItem = {}
    tableItem.operateEvent = eventName
    tableItem.name = name
    tableItem.eventList = changeEventList
    inputChangeEventControlObj(thisObj, tableItem, globalData)
  }
}

// export function processCustomCell(thisObj, record, rowIndex) {
//   // console.log('processCustomCell',record);
//   return {
//     style: {
//       // 行背景色
//       'background-color': '#8fd0fa',
//       'cursor': 'pointer'
//     },
//     // record:{},
//     props: { S_FILE_NAME: '' },
//     on: {
//       // 鼠标单击行
//       click: event => {
//         const code = `function code(text,record,rowIndex,rowColumn){return record}`
//         const fun = new Function(`return ${code}`)()
//         const funResult = fun(record)
//         console.log('funResult', funResult)
//       }
//     }
//   }
// }
// export function processCustomRow(thisObj, record, rowIndex) {
//   thisObj.customRowIdxBtnObj[rowIndex] = processCustomRowColumnBtn(thisObj, record, thisObj.tableColumnBtn)
//   thisObj.customRowIdxMenuObj[rowIndex] = processCustomRowColumnBtn(thisObj, record, thisObj.tableColumnMenu)
//   return {
//     on: {
//       // 鼠标单击行
//       click: event => {
//         processCustomRowOnClick(thisObj, record, rowIndex)
//         // this.processCustomRowColumnBtn(record);
//       }
//     }
//   }
// }
export function processCustomRowOnClick(thisObj, globalData, rowIndex) {
  if (undefined !== thisObj.tableObjParam && thisObj.tableObjParam.rowOnClick === true) {
    thisObj.$emit(thisObj.tableEvent.rowOnClick, globalData)
  }
}
export function getBtnOperator(thisObj, globalData, btnItem) {
  if (btnItem === null) {
    return null
  }
  if (btnItem !== undefined && btnItem.operatorList !== undefined) {
    const operatorList = btnItem.operatorList
    if (operatorList.length === 0) {
      console.debug('只配置一条操作条件,不进行规则校验.')
      return operatorList[0]
    }
    for (const i in operatorList) {
      const operator = operatorList[i]
      if (operator.s_REF_FN_KEY !== undefined) {
        if (operator.s_REF_FN_KEY !== globalData.initSrcObj.initSrcLabel) {
          continue
        }
      }
      const el = operator.objEl
      const elFlag = evalEl(el, globalData.globalParam)
      console.log('elFlag', elFlag)
      if (elFlag) {
        return operator
      }
    }
    console.debug('配置', operatorList.length, '条操作条件,但都不满足条件.')
  }
  console.debug(btnItem, '未绑定操作地址.')
  return null
}

export function changeColumnFilterParam(thisObj) {
  for (const key in thisObj.columnFilterParam) {
    const filterObj = thisObj.columnFilterParam[key]
    const enumData = thisObj.activeEnumData[key]
    if (enumData === undefined) {
      if (filterObj instanceof Array) {
        thisObj.columnFilterParam[key] = filterObj.join()
      } else {
        thisObj.columnFilterParam[key] = filterObj
      }
    } else if (enumData !== undefined) {
      const newKeyVal = []
      const keyVal = []
      for (const i in filterObj) {
        const filterObjData = filterObj[i]
        console.log('filterObjData',filterObjData)
        let filterEnumData = null
        for (const eIdx in enumData) {
          const enumObj = enumData[eIdx]
          console.log('enumObj.value',enumObj.value)
          if (filterObjData === enumObj.value) {
            filterEnumData = enumObj
            break
          }
        }
        if (filterEnumData !== null) {
          if (key.endsWith('_text')) {
            const newKey = key.substr(0, key.lastIndexOf('_text'))
            newKeyVal.push(filterEnumData.value)
            keyVal.push(filterEnumData.text)
            thisObj.columnFilterParam[newKey] = newKeyVal.join()
            thisObj.columnFilterParam[key] = keyVal.join()
          } else {
            const newKey = key + '_text'
            newKeyVal.push(filterEnumData.text)
            keyVal.push(filterEnumData.value)
            thisObj.columnFilterParam[newKey] = newKeyVal.join()
            thisObj.columnFilterParam[key] = keyVal.join()
          }
        }
      }
    }
  }
}

export function fetchPageData(thisObj, globalData) {
  changeColumnFilterParam(thisObj)
  console.log('  thisObj.columnFilterParam', thisObj.columnFilterParam)
  const btnItem = globalData.clickItem
  let urlKey = 'page'
  const operator = getBtnOperator(thisObj, globalData, btnItem)
  console.debug('btn operator', operator)
  let operatorDefVal = {}
  if (operator !== undefined && operator !== null) {
    urlKey = operator.s_REF_URL_KEY
    operatorDefVal = getOperatorDefVal(thisObj, operator.refSetOpenVal)
  }
  let postParam = getRemoteUrlParam(thisObj, urlKey, globalData)
  const defVal = getBtnDefVal(thisObj, btnItem)
  postParam = Object.assign(postParam, defVal, operatorDefVal)
  const verify = getCommonRemoteUrlVerify(thisObj, urlKey, postParam)
  if (verify === 1) {
    // 查询验证未通过
    return
  }
  if (postParam === null || postParam.S_PAGE_ID === '') {
    return
  }
  thisObj.loading = true
  if (Object.keys(thisObj.columnOrderParam).length > 0) {
    postParam.columnOrderParam = thisObj.columnOrderParam
  }
  if (Object.keys(thisObj.columnFilterParam).length > 0) {
    postParam = Object.assign({}, postParam, thisObj.columnFilterParam)
  }
  let iPageNo = 1
  let iPageSize = 100
  if (thisObj.tablePagination !== undefined) {
    iPageNo = thisObj.tablePagination.current
    iPageSize = thisObj.tablePagination.pageSize
  }
  postParam.iPageNo = iPageNo
  postParam.iPageSize = iPageSize
  thisObj.spinning = true
  submitDealReq(postParam).then((res) => {
    thisObj.tableData = Object.assign([], [])
    if (res.data.success) {
      if (res.data.columnsList !== undefined) {
        thisObj.initUiVal.columnsList = res.data.columnsList
        changeListColActiveData(thisObj, thisObj.openParam)
        initListColActive(thisObj, thisObj.openParam)
      }
      thisObj.tableData = res.data.data
      changeTablePagination(thisObj)
    } else {
      thisObj.$message.warning(res.data.message)
      // handleVerifyErrorTips(thisObj, res.data)
    }
    thisObj.spinning = false
    thisObj.loading = false
  }).catch(reason => {
    console.log('reason' + reason)
  })
}

export function searchSessionTpl(thisObj, globalData) {
  const btnItem = globalData.clickItem
  let urlKey = 'loadSessionTpl'
  const operator = getBtnOperator(thisObj, globalData, btnItem)
  console.debug('btn operator', operator)
  let operatorDefVal = {}
  if (operator !== undefined && operator !== null) {
    urlKey = operator.s_REF_URL_KEY
    operatorDefVal = getOperatorDefVal(thisObj, operator.refSetOpenVal)
  }
  let postParam = getRemoteUrlParam(thisObj, urlKey, globalData)
  const defVal = getBtnDefVal(thisObj, btnItem)
  postParam = Object.assign(postParam, defVal, operatorDefVal)
  const verify = getCommonRemoteUrlVerify(thisObj, urlKey, postParam)
  if (verify === 1) {
    // 查询验证未通过
    return
  }
  if (postParam === null || postParam.S_PAGE_ID === '') {
    return
  }
  thisObj.loading = true
  submitDealReq(postParam).then((res) => {
    if (res.data.success) {
      thisObj.initUiVal.sessionData = Object.assign({}, res.data.data)
      changeToolbar(thisObj, null, thisObj.globalData)
      changeToolbarMenu(thisObj, null, thisObj.globalData)
      changeListColActiveData(thisObj, thisObj.globalData)
      initListColActive(thisObj, thisObj.globalData)
      changeFormRowActiveData(thisObj, thisObj.globalData)
      initColumnListBtn(thisObj)
    } else {
      thisObj.$message.warning(res.data.message)
    }
    thisObj.loading = false
  }).catch(reason => {
    console.log('reason' + reason)
  })
}
export function loadSessionFormData(clickItem, thisObj, globalData) {
  const parameter = {}
  parameter.loadFormDataId = clickItem.id
  initSessionFormDataMethod(parameter).then((res) => {
    const sessionFormData = res.data.data
    if (sessionFormData.formData !== undefined) {
      thisObj.formModel = Object.assign({}, thisObj.formModel, sessionFormData.formData)
    }
    if (sessionFormData.sessionData !== undefined) {
      thisObj.initUiVal.sessionData = sessionFormData.sessionData
    } else {
      thisObj.initUiVal.sessionData = {}
    }
    changeToolbar(thisObj, null, thisObj.globalData)
    changeToolbarMenu(thisObj, null, thisObj.globalData)
    changeListColActiveData(thisObj, thisObj.globalData)
    initListColActive(thisObj, thisObj.globalData)
    changeFormRowActiveData(thisObj, thisObj.globalData)
    initColumnListBtn(thisObj)
  })
}

export function loadSessionUIData(clickItem, thisObj, globalData) {
  const parameter = {}
  parameter.loadSessionTplId = clickItem.id
  initSessionUIDataMethod(parameter).then((res) => {
    const sessionFormData = res.data.data
    if (sessionFormData.formData !== undefined) {
      thisObj.formModel = Object.assign({}, thisObj.formModel, sessionFormData.formData)
    }
    if (sessionFormData.sessionData !== undefined) {
      thisObj.initUiVal.sessionData = sessionFormData.sessionData
    } else {
      thisObj.initUiVal.sessionData = {}
    }
    changeToolbar(thisObj, null, thisObj.globalData)
    changeToolbarMenu(thisObj, null, thisObj.globalData)
    changeListColActiveData(thisObj, thisObj.globalData)
    initListColActive(thisObj, thisObj.globalData)
    changeFormRowActiveData(thisObj, thisObj.globalData)
    initColumnListBtn(thisObj)
  })
}

export function beforeInitData(thisObj, globalData) {
  searchSessionFormData(thisObj, globalData)
}

export function searchSessionFormData(thisObj, globalData) {
  const btnItem = globalData.clickItem
  let urlKey = 'loadSessionFormData'
  const operator = getBtnOperator(thisObj, globalData, btnItem)
  console.debug('btn operator', operator)
  let operatorDefVal = {}
  if (operator !== undefined && operator !== null) {
    urlKey = operator.s_REF_URL_KEY
    operatorDefVal = getOperatorDefVal(thisObj, operator.refSetOpenVal)
  }
  let postParam = getRemoteUrlParam(thisObj, urlKey, globalData)
  const defVal = getBtnDefVal(thisObj, btnItem)
  postParam = Object.assign(postParam, defVal, operatorDefVal)
  const verify = getCommonRemoteUrlVerify(thisObj, urlKey, postParam)
  if (verify === 1) {
    // 查询验证未通过
    return
  }
  if (postParam === null || postParam.S_PAGE_ID === '') {
    return
  }
  thisObj.loading = true
  submitDealReq(postParam).then((res) => {
    if (res.data.success) {
      thisObj.formModel = Object.assign({}, {}, res.data.data)
      thisObj.tableQueryByParam(thisObj.formMode)
    } else {
      thisObj.$message.warning(res.data.message)
    }
    thisObj.loading = false
  }).catch(reason => {
    console.log('reason' + reason)
  })
}

/**
 * 处理分页信息
 * @param thisObj
 */
export function changeTablePagination(thisObj) {
  if (undefined !== thisObj.tableData) {
    for (const i in thisObj.tableData) {
      thisObj.processCustomRow(thisObj.tableData[i], i)
    }
    if (undefined !== thisObj.tableData[0]) {
      thisObj.tableSelectedKey = []
      thisObj.tableFirstRow = thisObj.tableData[0]
      // const tableRowKey = thisObj.tableRowKey
      // const pk = thisObj.tableData[0][tableRowKey]
      // thisObj.tableSelectedKey.push(pk)
      thisObj.tablePagination.total = thisObj.tableData[0].totalCount
    } else {
      thisObj.tableFirstRow = {}
      thisObj.tablePagination.total = 0
    }
  } else {
    thisObj.tableFirstRow = {}
    thisObj.tablePagination.total = 0
  }
}

export function changeLoadRemoteModel(thisObj, data) {
  const h = thisObj.$createElement
  thisObj.$info({
    title: 'This is a notification message',
    content: h('div', {}, [
      h('p', 'some messages...some messages...'),
      h('p', 'some messages...some messages...')
    ]),
    onOk() {}
  })
}

export function changeLoadRemoteSuccess(thisObj, eventObj, data) {
  const urlKey = eventObj.s_RULE_TPL_KEY
  if (urlKey === 'page') {
    changeTablePagination(thisObj)
  } else if (urlKey === 'list') {
    changeTablePagination(thisObj)
  }
}

export function callRemoteData(thisObj, urlKey, eventObj, globalData) {
  const param = getRemoteUrlParam(thisObj, urlKey, globalData)
  const urlDataSetKey = getRemoteUrlDataSetKey(thisObj, urlKey)
  thisObj.loading = true
  submitDealReq(param).then((res) => {
    if (res.data.success) {
      const tmpData = res.data[urlDataSetKey.S_GET_DATA_KEY]
      thisObj[urlDataSetKey.S_SET_DATA_KEY] = tmpData
      changeLoadRemoteSuccess(thisObj, eventObj, res.data)
      thisObj.$message.success(res.data.message)
    } else {
      thisObj.$message.warning(res.data.message)
    }
    thisObj.loading = false
  })
}

export function changeLoadRemoteData(thisObj, eventObj, globalData) {
  const urlKey = eventObj.s_RULE_TPL_KEY
  callRemoteData(thisObj, urlKey, eventObj, globalData)
}

export function getTableSelectRow(thisObj) {
  const tmpSelectedRow = thisObj.tableSelectedRow
  if (tmpSelectedRow.length === undefined) {
    return tmpSelectedRow
  } else {
    if (tmpSelectedRow.length === 0) {
      return null
    } else {
      return tmpSelectedRow[0]
    }
  }
}

export function changeSelectRowMergeParam(selectedRow, mergeParam) {
  const returnRows = []
  if (selectedRow.length === undefined) {
    // 非数组
    const row = Object.assign({}, mergeParam, selectedRow)
    return row
  } else {
    if (selectedRow.length === 0) {
      // returnRows.push(mergeParam)
      return returnRows
    } else {
      for (const idx in selectedRow) {
        const row = selectedRow[idx]
        returnRows.push(Object.assign({}, mergeParam, row))
      }
    }
  }
  return returnRows
}

export function changeSelectRow(thisObj, selectedRow) {
  const mergeParam = Object.assign({}, thisObj.openParam, thisObj.initData, thisObj.formModel)
  return changeSelectRowMergeParam(selectedRow, mergeParam)
}

/**
 * 初始化 主键
 * @param thisObj
 */
export function initTableRowKey(thisObj) {
  let tmpRowKey = 'S_ID'
  if (thisObj.initUiVal.tblList !== undefined) {
    if (thisObj.initUiVal.tblList.prop !== undefined) {
      if (thisObj.initUiVal.tblList.prop.S_ROW_KEY !== undefined) {
        tmpRowKey = thisObj.initUiVal.tblList.prop.S_ROW_KEY
      }
    }
  }
  thisObj.tableRowKey = tmpRowKey
}
